#include "FileManager.h"

CFileStorage::CFileStorage ( mString &a_sFileName )
{
    // Read the file content
    FILE *pInFile = NULL; 
    fopen_s(&pInFile, a_sFileName.c_str(), "rb");        
    /*if (pInFile == NULL)
        return E_FAIL;//return EPIC_FAIL xDD */

    if (pInFile == NULL)
    {
        (*g_pDebug) << "File Loading error: " << a_sFileName.c_str() << "\n";
        m_uFileSize    = 0;
        m_pFileContent = NULL;
    }
    else
    {
        // Get the file size
        fseek(pInFile, 0, SEEK_END);
        m_uFileSize = ftell(pInFile);
        fseek(pInFile, 0, SEEK_SET);

        // Get the file content
        m_pFileContent = new mChar[m_uFileSize];
        fread(m_pFileContent, 1, m_uFileSize, pInFile);
        fclose(pInFile);
        m_sFileName = a_sFileName;
    }    
}

CFileStorage::~CFileStorage ( )
{
    SAFE_DELETE(m_pFileContent);
}

const mChar* CFileStorage::Content ( )
{
    return m_pFileContent;
}

mUInt CFileStorage::ContentSize ( )
{
    return m_uFileSize;
}